<template>
  <div class="page-container">
    <page_breadcrumb :getKeyMethod="init_table_model" @change="change_table_model" pageOption />
    <ex_super_table_page v-bind="option" ref="SuperTablePage" @selection-change="e => selection = e">
    </ex_super_table_page>
    <print_returnGoodCode_generate ref="print_returnGoodCode_generate" />
  </div>
</template>
<script>
import superTablePageFunction from '@/mixin/super-table-page-function';
import emitOnFunction from '@/mixin/emit-on-function';

import page_table_model_manage from '@/mixin/page_table_model_manage';
let emitKey = 'returngood>manage'
import print_returnGoodCode_generate from '@/component/print/print_returnGoodCode_generate'
import business_function from "@/common/business_function";

export default {
  title: 'label_returnGood_order_list',
  mixins: [superTablePageFunction, emitOnFunction(emitKey), page_table_model_manage],
  components: { print_returnGoodCode_generate },
  data() {
    const status_enum = (this.$enumOptions['ReturnOrderStatusEnum'] ? this.$enumOptions['ReturnOrderStatusEnum'].filter(it => !['TO_BE_CLAIMED', 'CLAIMED',
      'INSPECTIONING', 'WAIT_PUTAWAY', 'PARTIAL_PUTAWAY',
      'UNDER_REVIEW', 'AUDIT_FAILURE', 'DESTROYED',
    ].includes(it)) : [])
    status_enum.splice(status_enum.indexOf("PROCESSING"), 1)
    status_enum.splice(status_enum.indexOf("COMPLETED"), 0, "PROCESSING")
    return {
      statusRadioGroup: (this.$enumOptions['ReturnOrderStatusEnum'] || []).filter(it => !['DRAFT'].includes(it)),
      selection: [],
      storeList: [],
      option: {
        search: {
          default: { status: "" },
          resetFieldFun: (def, org) => { def.status = org.status; return def },
          model: [
            {
              key: 'status',
              label: 'label_status',
              itemClass: "w_fill",
              enum: 'ReturnOrderStatusEnum',
              type: 'select',
              render: (h, { data }) => {
                const list = this.statusRadioGroup
                  .map(it => (
                    <el-radio-button key={it} label={it}>
                      {this.$enumShow(it, 'ReturnOrderStatusEnum')}
                    </el-radio-button>
                  ))
                return (<el-radio-group value={data.status}
                  onInput={e => {
                    this.$set(data, 'status', e)
                    this.$refs.SuperTablePage.loadDataForSearch()
                  }}>
                  <el-radio-button key="" label="">
                    {this.$tt("label_all")}
                  </el-radio-button>
                  {list}
                </el-radio-group>
                )
              }
            },

            { label: "label_return_order_code", key: "orderCodeList", placeholder: "tip_input_can_comma_separated", },
            { label: "label_customer", key: "customerId", type: 'common_customer_choose' },
            // { label: "label_warehouse", key: "warehouseId", type: "base_warehouse_select" },
            { label: "label_track_code", key: "trackNumberList", placeholder: "tip_input_can_comma_separated", },
            { label: "label_is_unclaimed", key: "isUnclaimed", type: "select", enum: 'YesOrNoEnum' },
            { label: "label_return_type", key: "returnType", type: "select", enum: 'ReturnRetTypeEnum' },
            { label: "label_platform", key: "platformCode", type: "select", enum: 'SrmOrderTypeEnum' },
            {
              label: "label_time_type", key: 'queryTimeType', type: 'select', enum: 'ReturnTimeQueryTypeEnum', fold: true,
              on: {
                change: (e) => {
                  if(!e){
                    this.$set(this.$refs.SuperTablePage.$refs.search.getData(), "timeFrom", null)
                    this.$set(this.$refs.SuperTablePage.$refs.search.getData(), "timeTo", null)
                  }
                }
              },
            },
            {
              key: 'timeFrom', label: "label_time_range", fold: true, type: 'date-picker', attrs: { type: 'datetime' },
              render: (h, { data, item }) => {
                const value = data[item.key]
                const limitKey = 'timeTo'
                const limitValue = data[limitKey]
                const disabledKey = 'queryTimeType'
                const disabledValue = !data[disabledKey]
                return (<ex_super_input value={value} disabled={disabledValue}  onInput={e => this.$set(data, item.key, e)} type="date-picker" placeholder="label_start_time"
                  attrs={{ type: 'datetime' }}
                  pickerOptions={{
                    disabledDate: date => { return limitValue ? (limitValue < date.getTime()) : false }
                  }}
                />)
              }

            },
            {
              key: 'timeTo', label: "~", fold: true, type: 'date-picker', attrs: { type: 'datetime' },
              render: (h, { data, item }) => {
                const value = data[item.key]
                const limitKey = 'timeFrom'
                const limitValue = data[limitKey]
                const disabledKey = 'queryTimeType'
                const disabledValue = !data[disabledKey]

                return (<ex_super_input value={value} disabled={disabledValue} onInput={e => this.$set(data, item.key, e)} type="date-picker" placeholder="label_end_time"
                  attrs={{ type: 'datetime', 'default-time': '23:59:59' }}
                  pickerOptions={{
                    disabledDate: date => { return limitValue ? (limitValue > date.getTime()) : false }
                  }}
                />)
              }
            },
            // { label: "label_is_destroy", key: "destroy", type: "select", enum: 'YesOrNoEnum', fold: true, },
            { label: "label_is_unpack", key: "needUnpacking", type: "select", enum: 'YesOrNoEnum', fold: true, },
            { label: "front_label_pack_pallet_code", key: "packageCode", fold: true, },
            { label: "label_platform_code", key: "platformOrderNo", fold: true, },
            { label: "label_ec_platform_code", key: "ecommerceOrderNo", fold: true, },
          ],
        },
        actionExtra: [
          {
            label: 'label_print_return_code',
            click: () => this.$refs.print_returnGoodCode_generate.show(),
          },
          { label: 'label_operate_log_report', click: this.exportExcel },
        ],
        table: {
          url: this.$url['wms/ReturnOrderList'],
          model: this.init_table_model(),
        },
      }
    };
  },



  methods: {
    option_table_model() {
      return [
        { type: 'selection', clickToggle: true, keyGroup: 'label_table_operate' },
        {
          key: 'code', label: 'label_return_order_code', 'show-overflow-tooltip': true,
          render: (h, { row, column }) => {
            const code = row[column.property]
            if (!code) return this.$tt('data_temp_none')
            return (<text_extra_tooltip_operate extra_barcode_image extra_text_align='center'
              value={code}
              data_type={column.property} data_id={row.id}
            />)
          },
        },
        {
          key: 'customerName', label: 'label_customer', 'show-overflow-tooltip': true,
          render: (h, { row, column }) => {
            return row.isUnclaimed === 'Y' ? '-' : row.customerName
          },
        },
        { key: 'customerCode', label: 'label_customer_code', 'show-overflow-tooltip': true, },
        { key: 'warehouseName', label: 'label_warehouse', 'show-overflow-tooltip': true, formatter: (r, c, v, i) => this.$formatNameCode(v, r.warehouseCode) },

        {
          key: 'trackingNumber', label: 'label_track_code', 'show-overflow-tooltip': true,
          render: (h, { row, column }) => {
            const code = row[column.property]
            if (!row[column.property]) return this.$tt('data_temp_none')
            return (<text_extra_tooltip_operate extra_barcode_image extra_text_align='center'
              value={code}
              data_type={column.property} data_id={row.id}
            />)
          },
        },
        { key: 'shopId', label: 'label_platform_store', 'show-overflow-tooltip': true, },
        {
          key: 'customerTrackingNumber', label: 'label_customer_track_code', 'show-overflow-tooltip': true,
          render: (h, { row, column }) => {
            const code = row[column.property]
            if (!row[column.property]) return this.$tt('data_temp_none')
            return (<text_extra_tooltip_operate extra_barcode_image extra_text_align='center'
              value={code}
              data_type={column.property} data_id={row.id}
            />)
          },
        },
        { key: 'status', label: 'label_status', formatter: (r, c, v, i) => this.$enumShow(v, "ReturnOrderStatusEnum") },
        { key: 'isUnclaimed', label: 'label_is_unclaimed', render: (h, s) => this.$renderText(h, s, { enum: "YesOrNoEnum", reverse: true, }) },
        { key: 'hasOwnerLessDestroy', label: 'label_unclaimed_destroy', render: (h, s) => this.$renderText(h, s, { enum: "YesOrNoEnum", reverse: true, }) },

        { key: 'gmtCreate', label: 'label_create_time', width: 140, formatter: (r, c, v, i) => this.$dateFormat(v) },
        { key: 'receiveTime', label: 'label_receiving_time', width: 140, formatter: (r, c, v, i) => this.$dateFormat(v) },
        { key: 'receiveUserName', label: 'label_receiving_operate_user', 'show-overflow-tooltip': true, },
        { key: 'acceptTime', label: 'label_inspection_time', width: 140, formatter: (r, c, v, i) => this.$dateFormat(v) },
        { key: 'acceptUserName', label: 'label_inspection_operate_user', 'show-overflow-tooltip': true, },
        { key: 'putawayTime', label: 'label_tms_complete_date', width: 140, formatter: (r, c, v, i) => this.$dateFormat(r.putawayTime || r.destroyTime) },
        { key: 'putawayUserName', label: 'label_operate_user', 'show-overflow-tooltip': true, formatter: (r, c, v, i) => r.putawayUserName || r.destroyUserName },
        { key: 'needDeleteQty', label: 'label_need_delete_qty', 'show-overflow-tooltip': true, },
        { key: 'needUnpacking', label: 'label_is_unpack', formatter: (r, c, v, i) => this.$enumShow(v, "YesOrNoEnum") },

        { key: 'platformName', label: 'label_platform', 'show-overflow-tooltip': true, },
        {
          key: 'platformOrderNo', label: 'label_platform_code', 'show-overflow-tooltip': true,
          render: (h, { row, column }) => {
            const code = row[column.property]
            if (!row[column.property]) return this.$tt('data_temp_none')
            return (<text_extra_tooltip_operate extra_barcode_image extra_text_align='center'
              value={code}
              data_type={column.property} data_id={row.id}
            />)
          },
        },
        { key: 'returnType', label: 'label_return_type', formatter: (r, c, v, i) => this.$enumShow(v, "ReturnRetTypeEnum") },
        {
          key: 'packageCode', label: 'front_label_pack_pallet_code', 'show-overflow-tooltip': true,
          render: (h, { row, column }) => {
            const code = row[column.property]
            if (!row[column.property]) return this.$tt('data_temp_none')
            return (<text_extra_tooltip_operate extra_barcode_image extra_text_align='center'
              value={code}
              data_type={column.property} data_id={row.id}
            />)
          },
        },
        {
          key: 'ecommerceOrderNo', label: 'label_ec_platform_code', 'show-overflow-tooltip': true,
          render: (h, { row, column }) => {
            const code = row[column.property]
            if (!row[column.property]) return this.$tt('data_temp_none')
            return (<text_extra_tooltip_operate extra_barcode_image extra_text_align='center'
              value={code}
              data_type={column.property} data_id={row.id}
            />)
          },
        },

        {
          type: 'operate', width: 160,
          operate: [
            {
              label: "label_tms_driver_view",
              click: (row) => this.clickDetail(row)
            },

          ]
        }
      ]
    },
    exportExcel() {
      business_function.confirmOperateBaseSelectOrForm.call(this, {
        data: this.$refs.SuperTablePage.getSearchData(),
        model: this.option.search.model,
        selection: this.selection,
        callback: (selection, data) => {
          let params = {}
          if (!_.isEmpty(selection)) {
            params = {
              idList: selection.map(it => it.id)
            }
          } else {
            params = data
          }
          this.$functionCommon({
            url: "/wms-api/refund/WmsReturnOrderRpc/orderExport.json",
            data: params,
            type: 'from'
          })
        }
      })
    },
    clickDetail(row) {

      this.$router.push({
        path: '/page/wms/returngoods/returngood_detail', query: { id: row.id, }
      })
    },

  }
};

</script>
<style></style>
